package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.framework.utils.ObjectCastUtil;
import com.molichuxing.services.infrastructure.bean.EscrowLogBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.EscrowLogMapper;
import com.molichuxing.services.infrastructure.dao.EscrowNotifyLogMapper;
import com.molichuxing.services.infrastructure.dto.response.EscrowLogDto;
import com.molichuxing.services.infrastructure.service.EscrowLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 第三方支付日志service
 *
 * @Author zoumingyu
 * @Date 2020年03月31日
 */
@Service("escrowLogService")
public class EscrowLogServiceImpl implements EscrowLogService {
    private static final Logger logger = LoggerFactory.getLogger(EscrowLogServiceImpl.class);

    @Resource
    private EscrowLogMapper escrowLogMapper;

    @Resource
    private EscrowNotifyLogMapper escrowNotifyLogMapper;

    /**
     * 分页获取支付日志信息
     *
     * @param params   商户号订单（付款流水号）：payNumber <br/>
     *                 请求时间：requestTime
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Paged<EscrowLogDto> getPage(Map<String, Object> params, int pageNum, int pageSize) throws Exception {
        // 开始时间-LocalDateTime
        params.put("requestTimeStart", ObjectCastUtil.castLocalDateTimeStart(params.get("startRequestTime")));
        // 结束时间-LocalDateTime
        params.put("requestTimeEnd", ObjectCastUtil.castLocalDateTimeEnd(params.get("endRequestTime")));

        long total = escrowLogMapper.getPageCount(params);
        List<EscrowLogBean> page = null;
        if (total > 0) {
            page = escrowLogMapper.getPage(params, pageNum, pageSize);
        }

        return new Paged<EscrowLogDto>(Convert.toEscrowLogDto(page), total, pageSize);
    }
}
